In standard , commands such as \section
have moving
arguments, that is, arguments that migrate to an auxiliary file jobname.aux
to be used later in typesetting the table of
contents and so on [#!Lamport!#, 33–34].
In this process, macros in the body of the argument
are expanded, so that when you type, say,
\section{Annoying \TeX nicalities}what goes into the auxiliary file is something like
\@writefile{toc}{\string\contentsline\space {chapter}{\string\numberline\space {1}Annoying T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emXnicalities}{1}}where the second line contains the expansion of the macro
\TeX
.
There are several problems with this. First, the expansion, and
consequently the line where it occurs in the auxiliary file, can be
very long, which in some implementations means that TEX cannot
read the line back in. Secondly, the expansion might not
make sense, or might do the wrong thing, at the time when it is read in again.
Even worse, the expansion
of \section{\small foo}
, for example, actually
causes an infinite loop.
to *Experienced users of TEX who want to know why this happens can try typing the following lines to plain TEX:
\def\foo{\let\bar\foo} \foo %Nothing much happens \immediate\write0{\foo} %Disaster strikesThe problem is that at the time of the
\write
no assignment is
taking place, so the \foo
at the end of the expansion is not
handled as a literal.
Standard 's solution to these problems is for the user to
precede ``fragile'' macros with the \protect
command
[#!Lamport!#, 33–34]. By contrast, in the geom
style,
you don't have to worry about ``fragile'' commands
in the following situations:
\chapter
, \section
, and so on;
theorem
environment and its relatives (Theorems and Their Friends);
\caption
, \fig
and its relatives
(PostScript Figures);
\markright
and \markboth
;
\cite
.
\protect
ed [#!Lamport!#, 151]. In future
versions I hope to extend this permissiveness to the remaining
situations.
Notice, however, that the \verb|...|
construction continues to
be forbidden inside arguments to most commands. This is due to
reasons deeply embedded in TEX itself, and is unlikely ever to
change.
to *In some circumstances you might want the old behavior of
macro expansion inside the argument of \chapter
, say.
For instance, you might have a locally defined macro whose definition
will be unknown at the time the table of contents is read.
In this case you can use the following construction:
\edef\mystring{...} % where ... stands for the argument to be expanded \expandafter\chapter\expandafter{\mystring}